﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MYSQL学习
{
    internal class OrderConfig : IEntityTypeConfiguration<Order>
    {
        public void Configure(EntityTypeBuilder<Order> builder)
        {
            //mysql
            //表名这里是小写的写入数据库也是小写            
            //表名这里是大写的写入数据库也是小写吗？可以设置吗
            //表字段这里是大写的写入数据库也是大写
            builder.ToTable("fa_order").HasComment("订单表");
            builder.Property(o => o.User_id)
                .HasDefaultValue(0)
                .HasComment("用户ID");
            builder.Property(o => o.Order_no)
                .HasComment("订单号")
                .IsRequired().IsUnicode();
            //表字段是int
            //builder.Property(o => o.State).HasConversion<int>();\
            /// 表字段是enum
            builder.Property(p => p.State)
                .HasComment("订单状态")
                .HasColumnType("enum('0','1','2','3')")
                .HasConversion(
                    v => v.ToString(),
                    v => (State)System.Enum.Parse(typeof(State), v));
            //全局查询筛选器 用于软删除
            builder.HasQueryFilter(o => o.IsDeleted == false)
                .HasComment("是否删除");
            builder.Property(o => o.Createtime)
                .HasDefaultValue(0)
                .HasComment("创建时间");
            builder.Property(o => o.Updatetime)
                .HasDefaultValue(0)
                .HasComment("更新时间");
            builder.Property(o => o.Paytime)
                .HasDefaultValue(0)
                .HasComment("支付时间");
            builder.Property(o => o.Peisongtime)
                .HasDefaultValue(0)
                .HasComment("接单时间");
        }
    }
}
